using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Validation;
using EntLibContrib.Validation.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;

namespace EntLibContrib.Validation
{

    [AttributeUsage(AttributeTargets.Property
    | AttributeTargets.Field
    | AttributeTargets.Method
    | AttributeTargets.Parameter,
    AllowMultiple = true,
    Inherited = false)]
    public sealed class ExternallyConfiguredObjectValidatorAttribute : ValidatorAttribute
    {
        private readonly string targetRuleSet;
        private readonly string targetConfigFile;

        public ExternallyConfiguredObjectValidatorAttribute(string configurationFilePath)
            : this(string.Empty, configurationFilePath)
        {
        }

        public ExternallyConfiguredObjectValidatorAttribute(string ruleSet, string configurationFilePath)
        {
            targetConfigFile = configurationFilePath;
            targetRuleSet = ruleSet;
        }

        protected override Validator DoCreateValidator(Type targetType)
        {
            return new ExternallyConfiguredObjectValidator(targetRuleSet, targetConfigFile);
        }
    }
}
